package com.rede.didiok.user.modulelist.rank.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rede.didiok.user.modulelist.rank.entity.RankCategoryEntity;
import com.rede.didiok.user.modulelist.rank.service.RankCategoryService;
import com.rede.didiok.user.modulelist.rank.vo.Catelog2Vo;


@Controller
public class IndexTempController {

    @Resource
    RankCategoryService rankCategoryService;


    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){

        System.out.println(""+Thread.currentThread().getId());
        //TODO 1、查出所有的1级分类
        List<RankCategoryEntity> categoryEntities =  rankCategoryService.getLevel1Categorys();

        // 视图解析器进行拼串：
        // classpath:/templates/ +返回值+  .html
        model.addAttribute("categorys",categoryEntities);
        return "index";
    }


    /**
     * 查询所有分类数据，并分级，然后封装成map格式
     * @return
     */
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String, List<Catelog2Vo>> getCatalogJson(){
        Map<String, List<Catelog2Vo>> catalogJson = rankCategoryService.getCatalogJson();
        return catalogJson;
    }



    @ResponseBody
    @GetMapping("/hello")
    public String hello(){

        return "hello";
    }


}
